﻿using System;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Server;

namespace NetBay.Core.BusinessEntities.Workflow
{
    [DataContract]
    public class WorkflowHisto : ReturnObject
    {
        private User _User = new User();

        /// <summary>
        /// Gets or sets the identifier.
        /// </summary>
        /// <value>The identifier.</value>
        [DataMember]
        public long Identifier { get; set; }

        /// <summary>
        /// Gets or sets the state.
        /// </summary>
        /// <value>The state.</value>
        [DataMember]
        public WorkflowState State { get; set; }

        /// <summary>
        /// Gets or sets the action label.
        /// </summary>
        /// <value>The state label.</value>
        [DataMember]
        public string ActionLabel { get; set; }

        /// <summary>
        /// Gets or sets the date action.
        /// </summary>
        /// <value>The date action.</value>
        [DataMember]
        public DateTime DateAction { get; set; }

        /// <summary>
        /// Gets or sets the full name of the histo user.
        /// </summary>
        /// <value>The full name of the histo user.</value>
        [DataMember]
        public string HistoUserFullName { get; set; }

        /// <summary>
        /// Gets or sets the name of the histo group.
        /// </summary>
        /// <value>The name of the sender group.</value>
        [DataMember]
        public string HistoGroupName { get; set; }

        /// <summary>
        /// Gets or sets the comment.
        /// </summary>
        /// <value>The comment.</value>
        [DataMember]
        public string Comment { get; set; }

        /// <summary>
        /// Gets or sets the name of the document.
        /// </summary>
        /// <value>The name of the document.</value>
        [DataMember]
        public string DocumentName { get; set; }

        /// <summary>
        /// Gets or sets the document id.
        /// </summary>
        /// <value>The document id.</value>
        [DataMember]
        public long DocumentId { get; set; }

        /// <summary>
        /// Gets or sets the sender.
        /// </summary>
        /// <value>The sender.</value>
        [Association("FK_HistoUser", "ForeignKey", "Key")]
        [Include]
        [DataMember]
        public User HistoUser
        {
            get { return _User; }
            set
            {
                ForeignKey = value.Key;
                _User = value;
            }
        }

        /// <summary>
        /// Gets or sets the identifier.
        /// </summary>
        /// <value>The identifier.</value>
        [DataMember]
        public long InstanceIdentifier { get; set; }

        /// <summary>
        /// Gets or sets the identifier.
        /// </summary>
        /// <value>The identifier.</value>
        [DataMember]
        public long ActionOrConditionId { get; set; }



        #region Public Functions

        public override object Clone()
        {
            return this.MemberwiseClone();
        }

        public override string ToString()
        {
            return string.Format("State: {0}, DateAction: {1}, User: {2}", State, DateAction, HistoUser);
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="WorkflowHisto" /> class.
        /// </summary>
        public WorkflowHisto()
            : base()
        {
            State = WorkflowState.None;
        }

        /// <summary>
        /// Only for error
        /// </summary>
        /// <param name="ErrorMessage"></param>
        public WorkflowHisto(string errorMessage, Exception applicationException = null)
            : base(errorMessage, applicationException)
        {
            State = WorkflowState.None;
        }
        #endregion


    }
}